home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_09 / welstea2 / cwdatobj.cpp < prev    next >
C/C++ Source or Header  |  1995-05-06  |  2KB  |  65 lines

  1. // File CWDATOBJ.CPP  Defines basic data objects
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. #include "cwobj.h"
  7. #include "cwdialgs.h"
  8.  
  9. void value_str(tdata_type data_type,
  10.      void *the_value_addr,int display_len,
  11.      char *the_string) {
  12.     switch (data_type) {
  13.     case STR_DATA:
  14.     case PATH_DATA:
  15.       strncpy (the_string,(char *)the_value_addr,
  16.          display_len);
  17.       the_string[display_len-1] = '\0';
  18.       break;
  19.     case COLOR_DATA:
  20.       sprintf (the_string,"RGB(%hu,%hu,%hu)",
  21.          GetRValue(*(DWORD *)the_value_addr),
  22.      GetGValue(*(DWORD *)the_value_addr),
  23.      GetBValue(*(DWORD *)the_value_addr));
  24.       break;
  25.     default:
  26.       strcpy (the_string,"");  }  //End switch
  27.       }  //End function
  28.  
  29. void build_display_str (tdata_type data_type,
  30.       void *descr_addr,void *value_addr,
  31.       int display_len,int maxlen,
  32.       char *the_string) {
  33.     char astring[256],the_value_str[MAX_DISPLAY_LEN];
  34.     strcpy (astring,(char *)descr_addr);
  35.     strcat (astring,": ");
  36.     value_str (data_type,value_addr,display_len,
  37.            the_value_str);
  38.     strcat (astring,the_value_str); 
  39.     strncpy (the_string,astring,maxlen-2);
  40.     the_string[maxlen-1] = '\0'; }
  41.  
  42. char *ttyped_data_obj::get_display_str (int maxlen){
  43.      // Build display_str in case value has changed.
  44.      build_display_str(data_type,descr_addr,value_addr,
  45.         display_len,maxlen,display_str);
  46.      return display_str; }
  47.  
  48. void ttyped_data_obj::get_new_value (HWND parent,
  49.         int maxlen) {
  50.     switch (data_type) {
  51.     case STR_DATA:
  52.       string_dialog (parent,descr_addr,descr_addr,
  53.           display_len,value_addr);
  54.       break;
  55.     case PATH_DATA:
  56.       get_file_name_dlg(parent,wild_str,
  57.       descr_addr,(char *)value_addr,MAX_PATH);
  58.       break;
  59.    case COLOR_DATA:
  60.       get_rgb_color (parent,(COLORREF *)value_addr);
  61.       break;
  62.       }  //end switch
  63.    get_display_str(maxlen);  }
  64.  
  65.